package edu.hitsz.prop;

import edu.hitsz.aircraft.AbstractEnemy;
import edu.hitsz.aircraft.HeroAircraft;
import edu.hitsz.application.Explode;
import edu.hitsz.bullet.AbstractBullet;
import edu.hitsz.observerpattern.Subscriber;

import java.util.ArrayList;
import java.util.List;

/**
 * 炸弹道具
 */
public class BombProp extends AbstractProp{
    private List<AbstractEnemy> explodeList = new ArrayList<>();
    private List<Subscriber> subscribers = new ArrayList<>();

    public BombProp(int locationX, int locationY, int speedX, int speedY) {
        super(locationX, locationY, speedX, speedY);
    }

    public void addSubscriber( List<AbstractEnemy> enemyAircrafts, List<AbstractBullet> enemyBullets) {
        subscribers.addAll(enemyAircrafts);
        subscribers.addAll(enemyBullets);
        explodeList.addAll(enemyAircrafts);
    }

    public void notice() {
        for (Subscriber subscriber : subscribers) {
            subscriber.update();
        }
    }

    @Override
    public void effect(HeroAircraft heroAircraft, List<Explode> explodes) {
        System.out.println("BombSupply active!!");
        notice();
        for(AbstractEnemy enemyAircraft : explodeList) {
            explodes.add(new Explode(enemyAircraft.getLocationX()-35,enemyAircraft.getLocationY()-50));
        }
    }
}
